#include "EZ_Thread.h"



void list_init(list_t *list)
{
	list->next = list->prev = list; 
}

void list_insert_after(list_t *list,list_t *node)
{
	list->next->prev = node;
	node->next = list->next;

	list->next = node;
	node->prev = list;
}

void list_insert_before(list_t *list,list_t *node)
{
	list->prev->next = node;
	node->prev = list->prev;
	
	list->prev = node;
	node->next = list;
}

void list_remove(list_t *node)
{
	node->prev->next = node->next;
	node->next->prev = node->prev;
	node->next = node->prev = node;
}

list_t* list_remove_next(list_t *node)
{
  list_t *tmp_node;
  
  if(node != node->next)
  {
    tmp_node = node->next;
    list_remove(node->next);
  }
  
  return tmp_node;

}

uint8_t list_isempty(list_t *node)
{
	if(node->next == node)
		return EZ_TRUE;
	return EZ_ERR;
}

uint32_t list_size(list_t *node)
{
	list_t *tmp_node;
	uint32_t size;
	
	size = 0;
	tmp_node = node;
	
	while(tmp_node->next != node)
	{
		size++;
		node = node->next;
	}

	return size;
}
